import  urllib.request
import  json


import jsonpath

url="https://www.taopiaopiao.com/cityAction.json?activityId&_ksTS=1743680207318_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true"


headers={
    "accept": "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01",
    # "accept-encoding": "gzip, deflate, br, zstd",
    "accept-language": "zh-CN,zh;q=0.9",
    "bx-v": "2.5.28",
    "cookie": "dnk=; t=036b1dcc8df81e03fb604e06fef55132; lgc=; sn=; _tb_token_=e3ef1b5774f89; cookie2=1452abca3d981c20b7fb96b20bbbe220; _nk_=; cna=wGB1IFTPrToCAXxPugDy0Ozo; xlly_s=1; isg=BKurf1m_SBxX7JRIf-fEV2FMOs-VwL9CsjMbER0oLOpBvMsepZJ7kgQaFvzSyxc6",
    "priority": "u=1, i",
    "referer": "https://www.taopiaopiao.com/",
    "sec-ch-ua": "\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"Google Chrome\";v=\"134\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
    "x-requested-with": "XMLHttpRequest"
}
request=urllib.request.Request(url,headers=headers)
response=urllib.request.urlopen(request)
if response.getcode()==200:
    content = response.read().decode('utf-8')
    content=content.split('(')[1].split(')')[0]
    json=json.loads(content)
    with open(file='region.json',mode='w',encoding='utf-8') as f:
        f.write(content)
    print(json)
    regionName_list = jsonpath.jsonpath(json, '$..regionName')
    print(regionName_list)
    print(len(regionName_list))
    name=jsonpath.jsonpath(json, '$..A[?(@.regionName==安庆)]')
    print(name)

